package railRoad.web.slaves;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import railRoad.Route;
import railRoad.Schedule;
import railRoad.Station;
import railRoad.web.slaves.interfaces.ISlaveServlet;

public class StationEditServlet implements ISlaveServlet {

	public void work(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		Map<?, ?> parameterMap = req.getParameterMap();

		if (parameterMap.containsKey("id_station")) {
			int id_station = Integer.parseInt(req.getParameterValues("id_station")[0]); 
			int id_route = (Integer) req.getSession().getAttribute("id_route");

			Schedule schedule = Schedule.getInstance();

			Route route = schedule.getRouteById(id_route);
			Station station = route.getStationById(id_station);

			req.getSession().setAttribute("station", station);
		}// if parameterMap
		resp.sendRedirect("/pages/station_edit.jsp");
	}// work

}// StationEditServlet
